import { CancelOrder } from "@/apis/consult"
import { OrderType } from "@/enums"
import type { ConsultOrderItem } from "@/types/consult"
import { showToast } from "vant"
import { ref } from "vue"

 export const useCancelOrder = ()=>{
  const cancelLoding = ref(false)
  //订单取消
  const orderCancel = async (item: ConsultOrderItem) => {
    try {
      
        cancelLoding.value = true
        await CancelOrder(item.id)
        item.status = OrderType.ConsultCancel
        item.statusValue = '已取消'
        showToast('取消成功')
      
    } catch (error) {
      showToast('取消失败')
    }
    finally {
      cancelLoding.value = false
    }
  }
  return{
    cancelLoding,
    orderCancel
  }
}